<template>
  <a-form
    :model="formState"
    ref="formDataRef"
    name="basic"
    :label-col="{ style: 'width:90px' }"
    :wrapper-col="{ style: 'calc(100% - 90px)' }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="运输商名称" name="carrier" :rules="[{ required: true, message: '请填写运输商名称!' }]">
      <a-input v-model:value="formState.carrier" placeholder="请输入运输商名称" />
    </a-form-item>
    <a-form-item label="运输商代码" name="carrierCode" :rules="[{ required: true, message: '请填写运输商代码!' }]">
      <a-input v-model:value="formState.carrierCode" placeholder="请输入运输商代码" />
    </a-form-item>
    <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
      <a-button :loading="loading" type="primary" html-type="submit">确定</a-button>
      <a-button @click="resetHandle">取消</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts" setup>
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: Carrier.ListRows;
    type: number;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", blo: boolean): void;
  (e: "submit"): void;
}>();
const { visible, passData, type } = toRefs(props);
const { formDataRef, formState, loading } = InitHook();
const { onFinish, onFinishFailed, resetFields, resetHandle } = OperationHook({ formDataRef, formState, passData, emit, type, loading });
const init = () => {
  if (type.value === 2) {
    Object.assign(formState, passData.value);
  }
};
watch(
  () => visible.value,
  (v: boolean) => {
    if (v) {
      init();
    } else {
      resetFields();
      formDataRef.value.clearValidate();
    }
  }
);
init();
</script>
<style lang="stylus" scoped>
:deep(.ant-input-number){
    width: 100%;
}
</style>
